package com.bw.zg3park2212.carmanger

import androidx.lifecycle.MutableLiveData
import com.bw.base.db.SearchDao
import com.bw.base.db.SearchEntity
import com.bw.base.entity.CarmangerAddParam
import com.bw.base.entity.CarmangerEntity
import com.bw.base.mvvm.BaseViewModel
import com.bw.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class CarMangerViewModel@Inject constructor(val  apiService: ApiService,val searchDao: SearchDao):BaseViewModel() {
    var caridSuccse=MutableLiveData<CarmangerEntity>()
    fun carid(id:Int){
        httpRequst(
            {apiService.getCarId(id)},
            caridSuccse::postValue
        )
    }
    var carcodeSuccse=MutableLiveData<CarmangerEntity>()
    fun carcode(code:String){
        httpRequst(
            {apiService.getCodeCar(code)},
            carcodeSuccse::postValue
        )
    }
    var carAddSuccse=MutableLiveData<CarmangerEntity>()
    fun carAdd(body:CarmangerAddParam){
        httpRequst(
            {apiService.getaddcarmanger(body)},
            carAddSuccse::postValue
            )

    }
    var carDelSuccse=MutableLiveData<Boolean>()
    fun cardel(id:Int){
        httpRequst(
            {apiService.getDelCarmanger(id)},
            carDelSuccse::postValue
        )
    }
    var carmanupSuccse=MutableLiveData<CarmangerEntity>()
    fun carmanup(id:Int,body:CarmangerAddParam){
        httpRequst(
            {apiService.getUpCarmanger(id,body)},
            carmanupSuccse::postValue
        )
    }
    var addsearchSuccse=MutableLiveData<Long>()
    fun addserch(searchEntity: SearchEntity){
        roomRequst(
            {searchDao.insert(searchEntity)},
            addsearchSuccse::postValue
        )
    }
    var querysearchSuccse=MutableLiveData<List<SearchEntity>>()
    fun queryserch(){
        roomRequst(
            {searchDao.queryAll()},
            querysearchSuccse::postValue
        )
    }
    var delsearchSuccse=MutableLiveData<Int>()
    fun delsearch(searchEntity: SearchEntity){
        roomRequst(
            {searchDao.delete(searchEntity)},
            delsearchSuccse::postValue)
    }

}